from flask import Flask, request, jsonify

from router.food_routes import food_bp
from router.user_routes import user_bp
from service.sqlService import get_database_info, create_llm_prompt, get_sql_from_llm

app = Flask(__name__)

@app.route('/text_to_sql', methods=['POST'])
def text_to_sql():
    data = request.get_json()
    user_query = data.get('query')
    data_info = get_database_info()
    prompt = create_llm_prompt(user_query, data_info)
    sql_query = get_sql_from_llm(prompt)
    #sql_query = ""
    return jsonify({
        "msg": "success",
        "code": 0,
        "data": {
            "query": user_query,
            "sql": sql_query
        }
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001)
